//
//  WKLunchImageTools.m
//  WeKeTang
//
//  Created by ichina on 2017/8/22.
//  Copyright © 2017年 Dezhi Tiancheng Education Technology (Beijing) Co. Ltd. All rights reserved.
//

#import "WKLunchImageTools.h"

@implementation WKLunchImageTools

+ (void)animWithWindow:(UIWindow *)window image:(UIImage *)image{
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    imageView.image = image == nil?[self getLunchImage]:image;
    
    [window.rootViewController.view addSubview:imageView];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [UIView animateWithDuration:0.2 animations:^{
            
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            
            imageView.transform = CGAffineTransformMakeScale(2.f, 2.f);
            imageView.alpha = 0;
            
        }completion:^(BOOL finished) {
            
            [imageView removeFromSuperview];
        }];
        
    });
    
    
}

+ (UIImage*)getLunchImage{
    
    NSString *imageName = @"LaunchImage-700";
    
    if (iPhone5) {
        imageName = @"LaunchImage-700-568h";
    }
    if (iPhone6 | iPhone6s | iPhone7) {
        
        imageName = @"LaunchImage-800-667h";
    }
    
    if (iPhone6Plus | iPhone6sPlus | iPhone7Plus) {
        imageName = @"LaunchImage-800-Portrait-736h";
    }
    
    UIImage * image = [UIImage imageNamed:imageName];
    
    //NSAssert(image != nil, @"温馨提示：请添加启动图片");
    
    return image;
}

@end
